package pe.edu.upc.dsd.rs;


import java.io.BufferedReader;
import java.io.InputStreamReader;

import junit.framework.Assert;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;


public class RestPruebasUnitariasAllService {
	@Test	
	
	public void prueba() throws Exception {
		HttpClient httpclient1 = new  DefaultHttpClient();
		HttpClient httpclient2 = new  DefaultHttpClient();
		HttpClient httpclient3 = new  DefaultHttpClient();
		

		HttpGet httpget1 = new HttpGet("http://localhost:8080/rs-server-consolida/rest/rentvideo/usuario");
		HttpGet httpget2 = new HttpGet("http://localhost:8080/rs-server-consolida/rest/soundtrack/usuario");
		HttpGet httpget3 = new HttpGet("http://localhost:8080/rs-server-consolida/rest/trailers/usuario");
		
		HttpResponse response1 = httpclient1.execute(httpget1);
		HttpResponse response2 = httpclient2.execute(httpget2);
		HttpResponse response3 = httpclient3.execute(httpget3);
		
				
		HttpEntity entity1 = response1.getEntity();
		HttpEntity entity2 = response2.getEntity();
		HttpEntity entity3 = response3.getEntity();
		
		BufferedReader reader1 = new BufferedReader(new InputStreamReader(entity1.getContent()));
		BufferedReader reader2 = new BufferedReader(new InputStreamReader(entity2.getContent()));
		BufferedReader reader3 = new BufferedReader(new InputStreamReader(entity3.getContent()));
		
		String  jsontext1 =reader1.readLine();		
		String  jsontext2 =reader2.readLine();
		String  jsontext3 =reader3.readLine();
		
		// pinta en el log del servidor1
		System.out.println(jsontext1 );
		// pinta en el log del servidor2
		System.out.println(jsontext2 );
		// pinta en el log del servidor3
		System.out.println(jsontext3 );
		
		Assert.assertEquals(true,  jsontext1.length() > 0 && jsontext2.length() > 0 && jsontext3.length() > 0 );		
		
	}	
}